package com.qumap.item;

import com.google.gwt.event.shared.EventBus;
import com.qumap.item.event.ItemEventCollection;
import com.qumap.item.event.ItemEvent;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 13.06.11
 * Time: 18:57
 * To change this template use File | Settings | File Templates.
 */
public abstract class ItemInfoFactory<I extends ItemInfo> {

    private EventBus global_event_bus;

	public abstract List<I> getItemInfoList();

    public void setEventBus(EventBus global_event_bus) {
        this.global_event_bus = global_event_bus;
    }

    public void init() {
        for(I info: getItemInfoList()) {
            info.setEventBus(global_event_bus);
            info.init();
            sendItemRegisteredEvent(info);
        }
    }

    private void sendItemRegisteredEvent(ItemInfo info) {
        ItemEvent item_registered_event = ItemEventCollection.getCollection().getEvent(ItemEventCollection.EventType.ItemTypeRegistered);
        item_registered_event.add(new ItemOnMap(info));
        global_event_bus.fireEvent(item_registered_event);
    }
}
